package com.example.springworkfront.controller;

import com.example.springworkfront.Entity.Household;
import com.example.springworkfront.Service.HouseholdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.Part;
import java.io.File;
import java.io.IOException;


/**
 * Created by Administrator on 2018\9\8 0008.
 */
@RestController
@RequestMapping("/household")
public class HouseholdController {

    @Autowired
    private HouseholdService householdService;

    @RequestMapping("/checkopenid")
    public  String checkopenid (String openid){
        return householdService.checkopenid(openid);
    }

    @RequestMapping("/getopenid")
    public String getopenid(String code){
        return householdService.getopenid(code);
    }
    @RequestMapping("/upload")
    public String upload(HttpServletRequest request, @RequestParam(value = "file", required = false) MultipartFile file,
                       String account,String password,String name,String id_card,String room_number,
    String openid,String phone) throws IOException, ServletException {
        return householdService.upload(file,account,password,name,id_card,room_number,openid,phone);
    }
    @RequestMapping("/getqrcode")
    public String getqrcode(String account){
        return householdService.getqrcode(account);
    }

    @RequestMapping("/editimage")
    public String editimage( @RequestParam(value = "file", required = false) MultipartFile file,
                         String account) throws IOException {
        String filename=account+".png";
        File filex  =  new File("/tmp/",filename);
        file.transferTo(filex);
        System.out.println(filename);
        return "success";
    }

}


